package test;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import com.eb.bi.common.PluginExitCode;
import com.eb.bi.common.PluginResult;
import com.eb.bi.common.PluginUtil;
import com.eb.bi.common.util.CommonProcessor;
import com.eb.bi.common.util.DateProcessor;
import com.eb.bi.common.util.LoggerProcessor;

public class ReadFiletest {
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		boolean ret = true;
		long beginTime = System.currentTimeMillis();
		
		PluginUtil.getInstence().init(args);
		String input_sources ="";
		try {
			input_sources = PluginUtil.getInstence().getPluginConfig().getM_params().get("input_sources").trim();
			FileReader fr = new FileReader(input_sources);
			BufferedReader br = new BufferedReader(fr);
			String s = "";
			try {
				while((s = br.readLine())!= null){
					System.out.println(s.split("\\|")[0]+"   "+s.split("\\|")[1]);
					LoggerProcessor.getLogInstance().info("read data is "+s.split("\\|")[0]+" "+s.split("\\|")[1]);
				}
				DateProcessor DateProcessor = new DateProcessor();
				long endTime = System.currentTimeMillis();
				
				PluginResult.getInstance().setEndTime(DateProcessor.getNowFullTime());
	
				PluginResult.getInstance().setTimeCosts(CommonProcessor.getCostTime(beginTime, endTime));
	
				PluginResult.getInstance().setExitCode(ret ? String.valueOf(PluginExitCode.PE_SUCC): String.valueOf(PluginExitCode.PE_LOGIC_ERR));
				PluginResult.getInstance().setExitDesc(ret ? "run successfully" : "run failed.");
				PluginResult.getInstance().addOtherParam("xxxxx", "xxx");
				PluginResult.getInstance().save();
			} catch (IOException e) {
				LoggerProcessor.getLogInstance().error(input_sources+" read faild. [Reason: io exception]");
				ret =false;
			}
		} catch (FileNotFoundException e) {
			LoggerProcessor.getLogInstance().error(input_sources+" load faild. [Reason: file not found exception]");
			ret = false;
		}
	}
}
